﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static FinalsArithmetic.Test.Calculate;

namespace FinalsArithmetic.Test
{
	class Program
	{
		static void Main(string[] args)
		{
			int TotalCount = 32;
			var calculate = new Calculate(TotalCount, GetMatchInfoList());

			var seatList = calculate.GetSeatInfoList();

			var newSeatList = seatList.Where(m => m.AnchorId > 0).ToList();
			//判断生成的方案是否有重复
			var distinctList = newSeatList.Where((x, i) => newSeatList.FindIndex(z => z.AnchorId == x.AnchorId) == i).ToList();

			if (distinctList.Count() != newSeatList.Count())
			{
				throw new Exception("生成的方案有重复");
			}

			var seatStr = seatList.Select(m => new SeatInfo
			{
				SeatId = m.SeatId,
				Anchor = GetAnchors(TotalCount).FirstOrDefault(k => k.AnchorId == m.AnchorId)
			}).JsonSerialize();

			
		}

		/// <summary>
		/// 获取人工匹配信息列表
		/// </summary>
		public static List<MatchInfo> GetMatchInfoList()
		{
			//直接按照优先级加入列表
			List<MatchInfo> matchInfoList = new List<MatchInfo>();

			//matchInfoList.Add(new MatchInfo { FinalsId = 4, AnchorId1 = 1, AnchorId2 = 2 });
			//matchInfoList.Add(new MatchInfo { FinalsId = 4, AnchorId1 = 1, AnchorId2 = 3 });
			//matchInfoList.Add(new MatchInfo { FinalsId = 4, AnchorId1 = 4, AnchorId2 = 5 });
			//matchInfoList.Add(new MatchInfo { FinalsId = 4, AnchorId1 = 6, AnchorId2 = 7 });
			//matchInfoList.Add(new MatchInfo { FinalsId = 4, AnchorId1 = 8, AnchorId2 = 9 });

			//matchInfoList.Add(new MatchInfo { FinalsId = 8, AnchorId1 = 2, AnchorId2 = 3 });
			//matchInfoList.Add(new MatchInfo { FinalsId = 8, AnchorId1 = 1, AnchorId2 = 10 });
			//matchInfoList.Add(new MatchInfo { FinalsId = 8, AnchorId1 = 11, AnchorId2 = 12 });
			//matchInfoList.Add(new MatchInfo { FinalsId = 8, AnchorId1 = 13, AnchorId2 = 14 });
			//matchInfoList.Add(new MatchInfo { FinalsId = 8, AnchorId1 = 15, AnchorId2 = 16 });


			//matchInfoList.Add(new MatchInfo { FinalsId = 4, AnchorId1 = 1, AnchorId2 = 2 });
			//matchInfoList.Add(new MatchInfo { FinalsId = 4, AnchorId1 = 1, AnchorId2 = 3 });
			//matchInfoList.Add(new MatchInfo { FinalsId = 4, AnchorId1 = 3, AnchorId2 = 4 });
			//matchInfoList.Add(new MatchInfo { FinalsId = 4, AnchorId1 = 5, AnchorId2 = 6 });
			//matchInfoList.Add(new MatchInfo { FinalsId = 4, AnchorId1 = 7, AnchorId2 = 8 });
			//matchInfoList.Add(new MatchInfo { FinalsId = 4, AnchorId1 = 9, AnchorId2 = 10 });

			//matchInfoList.Add(new MatchInfo { FinalsId = 8, AnchorId1 = 1, AnchorId2 = 11 });
			//matchInfoList.Add(new MatchInfo { FinalsId = 8, AnchorId1 = 2, AnchorId2 = 12 });
			//matchInfoList.Add(new MatchInfo { FinalsId = 8, AnchorId1 = 3, AnchorId2 = 13 });
			//matchInfoList.Add(new MatchInfo { FinalsId = 8, AnchorId1 = 4, AnchorId2 = 14 });
			//matchInfoList.Add(new MatchInfo { FinalsId = 8, AnchorId1 = 15, AnchorId2 = 16 });
			//matchInfoList.Add(new MatchInfo { FinalsId = 8, AnchorId1 = 6, AnchorId2 = 17 });
			//matchInfoList.Add(new MatchInfo { FinalsId = 8, AnchorId1 = 7, AnchorId2 = 9 });
			//matchInfoList.Add(new MatchInfo { FinalsId = 8, AnchorId1 = 8, AnchorId2 = 10 });


			//matchInfoList.Add(new MatchInfo { FinalsId = 4, AnchorId1 = 1, AnchorId2 = 2 });
			//matchInfoList.Add(new MatchInfo { FinalsId = 4, AnchorId1 = 1, AnchorId2 = 3 });
			//matchInfoList.Add(new MatchInfo { FinalsId = 4, AnchorId1 = 1, AnchorId2 = 4 });
			//matchInfoList.Add(new MatchInfo { FinalsId = 4, AnchorId1 = 1, AnchorId2 = 5 });

			//matchInfoList.Add(new MatchInfo { FinalsId = 8, AnchorId1 = 3, AnchorId2 = 4 });


			matchInfoList.Add(new MatchInfo { FinalsId = 4, AnchorId1 = 1, AnchorId2 = 2 });
			matchInfoList.Add(new MatchInfo { FinalsId = 4, AnchorId1 = 1, AnchorId2 = 3 });

			matchInfoList.Add(new MatchInfo { FinalsId = 8, AnchorId1 = 4, AnchorId2 = 2 });


			//规则要从小到大排个序

			return matchInfoList;
		}

		/// <summary>
		/// 获取所有主播的信息（模拟数据）
		/// </summary>
		/// <returns></returns>
		public static List<Anchor> GetAnchors(int TotalCount)
		{
			List<Anchor> anchorList = new List<Anchor>();

			//anchorList.Add(new Anchor() { AnchorId = 1, AnchorName = "阿冷" });
			//anchorList.Add(new Anchor() { AnchorId = 2, AnchorName = "提莫" });
			//anchorList.Add(new Anchor() { AnchorId = 3, AnchorName = "一发" });
			//anchorList.Add(new Anchor() { AnchorId = 4, AnchorName = "钱小佳" });
			//anchorList.Add(new Anchor() { AnchorId = 5, AnchorName = "B总001" });
			//anchorList.Add(new Anchor() { AnchorId = 6, AnchorName = "大司马" });
			//anchorList.Add(new Anchor() { AnchorId = 7, AnchorName = "大鹌鹑" });
			//anchorList.Add(new Anchor() { AnchorId = 8, AnchorName = "小缘" });
			//anchorList.Add(new Anchor() { AnchorId = 9, AnchorName = "纳豆" });
			//anchorList.Add(new Anchor() { AnchorId = 10, AnchorName = "二珂" });
			//anchorList.Add(new Anchor() { AnchorId = 11, AnchorName = "小苏菲" });
			//anchorList.Add(new Anchor() { AnchorId = 12, AnchorName = "骚白" });
			//anchorList.Add(new Anchor() { AnchorId = 13, AnchorName = "YYF" });
			//anchorList.Add(new Anchor() { AnchorId = 14, AnchorName = "17shou" });
			//anchorList.Add(new Anchor() { AnchorId = 15, AnchorName = "339户外" });
			//anchorList.Add(new Anchor() { AnchorId = 16, AnchorName = "微山湖" });

			//anchorList.Add(new Anchor() { AnchorId = 1, AnchorName = "77580480" });
			//anchorList.Add(new Anchor() { AnchorId = 2, AnchorName = "309871" });
			//anchorList.Add(new Anchor() { AnchorId = 3, AnchorName = "77590690" });
			//anchorList.Add(new Anchor() { AnchorId = 4, AnchorName = "308859" });
			//anchorList.Add(new Anchor() { AnchorId = 5, AnchorName = "309869" });
			//anchorList.Add(new Anchor() { AnchorId = 6, AnchorName = "77580114" });
			//anchorList.Add(new Anchor() { AnchorId = 7, AnchorName = "309890" });
			//anchorList.Add(new Anchor() { AnchorId = 8, AnchorName = "309833" });
			//anchorList.Add(new Anchor() { AnchorId = 9, AnchorName = "309470" });
			//anchorList.Add(new Anchor() { AnchorId = 10, AnchorName = "309466" });
			//anchorList.Add(new Anchor() { AnchorId = 11, AnchorName = "309832" });
			//anchorList.Add(new Anchor() { AnchorId = 12, AnchorName = "309917" });
			//anchorList.Add(new Anchor() { AnchorId = 13, AnchorName = "309637" });
			//anchorList.Add(new Anchor() { AnchorId = 14, AnchorName = "309870" });
			//anchorList.Add(new Anchor() { AnchorId = 15, AnchorName = "305428" });
			//anchorList.Add(new Anchor() { AnchorId = 16, AnchorName = "273725" });
			//anchorList.Add(new Anchor() { AnchorId = 17, AnchorName = "309657" });

			//anchorList.Add(new Anchor() { AnchorId = 1, AnchorName = "阿冷" });
			//anchorList.Add(new Anchor() { AnchorId = 2, AnchorName = "提莫" });
			//anchorList.Add(new Anchor() { AnchorId = 3, AnchorName = "一发" });
			//anchorList.Add(new Anchor() { AnchorId = 4, AnchorName = "钱小佳" });
			//anchorList.Add(new Anchor() { AnchorId = 5, AnchorName = "B总001" });

			anchorList.Add(new Anchor() { AnchorId = 1, AnchorName = "1" });
			anchorList.Add(new Anchor() { AnchorId = 2, AnchorName = "2" });
			anchorList.Add(new Anchor() { AnchorId = 3, AnchorName = "3" });
			anchorList.Add(new Anchor() { AnchorId = 4, AnchorName = "4" });


			//anchorList手写模拟是否重复验证（思路：去重后对比之前的个数是否减少了）
			var newAnchorList = anchorList.Where((x, i) => anchorList.FindIndex(z => z.AnchorId == x.AnchorId || z.AnchorName == x.AnchorName) == i).ToList();
			if (newAnchorList.Count() != anchorList.Count())
			{
				throw new Exception("模拟异常，有重复值");
			}
			//模拟剩下的主播
			for (int i = (TotalCount - anchorList.Count() + 1); i <= TotalCount; i++)
			{
				anchorList.Add(new Anchor() { AnchorId = i, AnchorName = $"anchor_{i}" });
			}
			return anchorList;
		}
	}
}
